#
# this file was created by a computer. trust it.
#

# compiler tools
XILINX_VITIS ?= /opt/Xilinx/Vitis/2019.2
XILINX_XRT ?= /opt/xilinx/xrt
XILINX_VIVADO ?= /opt/Xilinx/Vivado/2019.2
XILINX_VIVADO_HLS ?= $(XILINX_VITIS)/Vivado_HLS

HOST_CXX ?= g++
VPP ?= ${XILINX_VITIS}/bin/v++
EMCONFIGUTIL = ${XILINX_VITIS}/bin/emconfigutil --od .
RM = rm -f
RMDIR = rm -rf

VITIS_PLATFORM = xilinx_u280_xdma_201920_1
VITIS_PLATFORM_PATH = $(VITIS_PLATFORM)

# host compiler global settings
CXXFLAGS += -std=c++0x -DVITIS_PLATFORM=$(VITIS_PLATFORM) -D__USE_XOPEN2K8 -I$(XILINX_XRT)/include/ -I$(XILINX_VIVADO)/include/ -I/home/zyh/workspace/graphHLS/src/BFS/host -I/home/zyh/workspace/graphHLS/src/BFS/libfpga -O0 -g -Wall -c -fmessage-length=0
LDFLAGS += -lxilinxopencl -lpthread -lrt -lstdc++ -lmpfr -lgmp -lhlsmc++-GCC46 -lIp_floating_point_v7_0_bitacc_cmodel -lIp_xfft_v9_1_bitacc_cmodel -lIp_fir_compiler_v7_2_bitacc_cmodel -lIp_dds_compiler_v6_0_bitacc_cmodel -L$(XILINX_XRT)/lib/ -L$(XILINX_VIVADO)/lnx64/tools/fpo_v7_0 -L$(XILINX_VIVADO)/lnx64/lib/csim -L$(XILINX_VIVADO)/lnx64/tools/dds_v6_0 -L$(XILINX_VIVADO)/lnx64/tools/fir_v7_0 -L$(XILINX_VIVADO)/lnx64/tools/fft_v9_1 -Wl,-rpath-link,$(XILINX_XRT)/lib -Wl,-rpath,$(XILINX_VIVADO)/lnx64/lib/csim -Wl,-rpath,$(XILINX_VIVADO)/lnx64/tools/fpo_v7_0 -Wl,-rpath,$(XILINX_VIVADO)/lnx64/tools/fft_v9_1 -Wl,-rpath,$(XILINX_VIVADO)/lnx64/tools/fir_v7_0 -Wl,-rpath,$(XILINX_VIVADO)/lnx64/tools/dds_v6_0

# hardware compiler shared settings
VPP_OPTS = --target sw_emu

#
# OpenCL kernel files
#

BINARY_CONTAINERS += binary_container_1.xclbin

BUILD_SUBDIRS += binary_container_1.build
BINARY_CONTAINER_1_OBJS += binary_container_1.build/readEdgesCU.xo
ALL_KERNEL_OBJS += binary_container_1.build/readEdgesCU.xo
BUILD_SUBDIRS += binary_container_1.build
BINARY_CONTAINER_1_OBJS += binary_container_1.build/vertexApply.xo
ALL_KERNEL_OBJS += binary_container_1.build/vertexApply.xo

ALL_MESSAGE_FILES = $(subst .xo,.mdb,$(ALL_KERNEL_OBJS)) $(subst .xclbin,.mdb,$(BINARY_CONTAINERS))

#
# host files
#

HOST_OBJECTS += src/BFS/host/data_helper.o
HOST_OBJECTS += src/BFS/host/graph.o
HOST_OBJECTS += src/BFS/host/he_mem.o
HOST_OBJECTS += src/BFS/host/host_graph.o
HOST_OBJECTS += src/BFS/host/host_graph_scheduler.o
HOST_OBJECTS += src/BFS/host/host_graph_sw_dataflow.o
HOST_OBJECTS += src/BFS/host/host_graph_sw_kernel.o
HOST_OBJECTS += src/BFS/host/host_graph_sw_mem.o
HOST_OBJECTS += src/BFS/host/host_graph_sw_partition.o
HOST_OBJECTS += src/BFS/host/host_graph_verification_apply.o
HOST_OBJECTS += src/BFS/host/host_graph_verification_gs.o
HOST_OBJECTS += src/BFS/host/host_run_one_iteration.o
HOST_OBJECTS += src/BFS/host/l3DataPrepare.o
HOST_OBJECTS += src/BFS/host/scheduler.o
HOST_OBJECTS += src/BFS/host/xcl.o

HOST_EXE = graphHLS

BUILD_SUBDIRS += src/BFS/host/

EMCONFIG_FILE = emconfig.json

#
# primary build targets
#

.PHONY: all clean
all: $(BINARY_CONTAINERS) $(HOST_EXE) $(EMCONFIG_FILE)

.NOTPARALLEL: clean

clean-host:
	-$(RM) $(HOST_EXE) $(HOST_OBJECTS)

clean-accelerators:
	-$(RM) $(BINARY_CONTAINERS) $(ALL_KERNEL_OBJS) $(ALL_MESSAGE_FILES)  $(EMCONFIG_FILE)
	-$(RM) *.xclbin.sh *.xclbin.info *.xclbin.link_summary*
	-$(RMDIR) $(BUILD_SUBDIRS)
	-$(RMDIR) .Xil

clean: clean-host clean-accelerators

.PHONY: incremental
incremental: all

include makeemconfig.mk

nothing:

#
# binary container: binary_container_1.xclbin
#

binary_container_1.build/readEdgesCU.xo: ../src/BFS/libfpga/graph_fpga_cu.cpp ../src/BFS/host/graph_fpga.h ../src/BFS/libfpga/fpga_global_mem.h ../src/BFS/libfpga/fpga_slice.h ../src/BFS/libfpga/fpga_gather.h ../src/BFS/libfpga/fpga_filter.h ../src/BFS/libfpga/fpga_process_edge.h ../src/BFS/libfpga/fpga_cache.h ../src/BFS/libfpga/fpga_edge_prop.h binary_container_1-readEdgesCU-compile.ini common-config.ini
	-@mkdir -p $(@D)
	-@$(RM) $@
	$(VPP) $(VPP_OPTS) --compile -I"$(<D)" --config common-config.ini --config binary_container_1-readEdgesCU-compile.ini -I/home/zyh/workspace/graphHLS/src/BFS/host -I/home/zyh/workspace/graphHLS/src/BFS/libfpga -o"$@" "$<"

binary_container_1.build/vertexApply.xo: ../src/BFS/libfpga/vertex_apply.cpp ../src/BFS/host/graph_fpga.h ../src/BFS/libfpga/fpga_global_mem_apply.h binary_container_1-vertexApply-compile.ini common-config.ini
	-@mkdir -p $(@D)
	-@$(RM) $@
	$(VPP) $(VPP_OPTS) --compile -I"$(<D)" --config common-config.ini --config binary_container_1-vertexApply-compile.ini -I/home/zyh/workspace/graphHLS/src/BFS/host -I/home/zyh/workspace/graphHLS/src/BFS/libfpga -o"$@" "$<"

binary_container_1.xclbin: $(BINARY_CONTAINER_1_OBJS) binary_container_1-link.ini common-config.ini
	-@echo $(VPP) $(VPP_OPTS) --link --sp  readEdgesCU_1.edges1:HBM[0]  --sp  readEdgesCU_1.edges2:HBM[1]  --sp  readEdgesCU_1.edges3:HBM[2]  --sp  readEdgesCU_1.edges4:HBM[3]  --sp  readEdgesCU_1.csrIndex1:HBM[4]  --sp  readEdgesCU_1.csrIndex2:HBM[5]    --sp  readEdgesCU_2.edges1:HBM[8]  --sp  readEdgesCU_2.edges2:HBM[9]  --sp  readEdgesCU_2.edges3:HBM[10]  --sp  readEdgesCU_2.edges4:HBM[11]  --sp  readEdgesCU_2.csrIndex1:HBM[12]  --sp  readEdgesCU_2.csrIndex2:HBM[13]    --sp  readEdgesCU_3.edges1:HBM[16]  --sp  readEdgesCU_3.edges2:HBM[17]  --sp  readEdgesCU_3.edges3:HBM[18]  --sp  readEdgesCU_3.edges4:HBM[19]  --sp  readEdgesCU_3.csrIndex1:HBM[20]  --sp  readEdgesCU_3.csrIndex2:HBM[21]    --sp  readEdgesCU_4.edges1:HBM[24]  --sp  readEdgesCU_4.edges2:HBM[25]  --sp  readEdgesCU_4.edges3:HBM[26]  --sp  readEdgesCU_4.edges4:HBM[27]  --sp  readEdgesCU_4.csrIndex1:HBM[28]  --sp  readEdgesCU_4.csrIndex2:HBM[29]    --sp  readEdgesCU_1.tmpVertexProp:HBM[6] --sp  readEdgesCU_1.bitMap:HBM[7]  --sp  readEdgesCU_2.tmpVertexProp:HBM[14] --sp  readEdgesCU_2.bitMap:HBM[15]  --sp  readEdgesCU_3.tmpVertexProp:HBM[22] --sp  readEdgesCU_3.bitMap:HBM[23]  --sp  readEdgesCU_4.tmpVertexProp:HBM[30] --sp  readEdgesCU_4.bitMap:HBM[31]  --kernel_frequency=250  --config common-config.ini --config binary_container_1-link.ini -o"$@" $(BINARY_CONTAINER_1_OBJS) > binary_container_1.xclbin.sh
	$(VPP) $(VPP_OPTS) --link --sp  readEdgesCU_1.edges1:HBM[0]  --sp  readEdgesCU_1.edges2:HBM[1]  --sp  readEdgesCU_1.edges3:HBM[2]  --sp  readEdgesCU_1.edges4:HBM[3]  --sp  readEdgesCU_1.csrIndex1:HBM[4]  --sp  readEdgesCU_1.csrIndex2:HBM[5]    --sp  readEdgesCU_2.edges1:HBM[8]  --sp  readEdgesCU_2.edges2:HBM[9]  --sp  readEdgesCU_2.edges3:HBM[10]  --sp  readEdgesCU_2.edges4:HBM[11]  --sp  readEdgesCU_2.csrIndex1:HBM[12]  --sp  readEdgesCU_2.csrIndex2:HBM[13]    --sp  readEdgesCU_3.edges1:HBM[16]  --sp  readEdgesCU_3.edges2:HBM[17]  --sp  readEdgesCU_3.edges3:HBM[18]  --sp  readEdgesCU_3.edges4:HBM[19]  --sp  readEdgesCU_3.csrIndex1:HBM[20]  --sp  readEdgesCU_3.csrIndex2:HBM[21]    --sp  readEdgesCU_4.edges1:HBM[24]  --sp  readEdgesCU_4.edges2:HBM[25]  --sp  readEdgesCU_4.edges3:HBM[26]  --sp  readEdgesCU_4.edges4:HBM[27]  --sp  readEdgesCU_4.csrIndex1:HBM[28]  --sp  readEdgesCU_4.csrIndex2:HBM[29]    --sp  readEdgesCU_1.tmpVertexProp:HBM[6] --sp  readEdgesCU_1.bitMap:HBM[7]  --sp  readEdgesCU_2.tmpVertexProp:HBM[14] --sp  readEdgesCU_2.bitMap:HBM[15]  --sp  readEdgesCU_3.tmpVertexProp:HBM[22] --sp  readEdgesCU_3.bitMap:HBM[23]  --sp  readEdgesCU_4.tmpVertexProp:HBM[30] --sp  readEdgesCU_4.bitMap:HBM[31]  --kernel_frequency=250  --config common-config.ini --config binary_container_1-link.ini -o"$@" $(BINARY_CONTAINER_1_OBJS)

#
# host rules
#

src/BFS/host/data_helper.o: ../src/BFS/host/data_helper.cpp ../src/BFS/host/host_graph_sw.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/graph.o: ../src/BFS/host/graph.cpp ../src/BFS/host/graph.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/he_mem.o: ../src/BFS/host/he_mem.cpp ../src/BFS/host/common.h ../src/BFS/host/he_mem.h ../src/BFS/host/he_mem_id.h ../src/BFS/host/he_mem_attr.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/host_graph.o: ../src/BFS/host/host_graph.cpp ../src/BFS/host/host_graph_sw.h ../src/BFS/host/host_run_one_iteration.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/host_graph_scheduler.o: ../src/BFS/host/host_graph_scheduler.cpp ../src/BFS/host/host_graph_sw.h ../src/BFS/host/host_graph_scheduler.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/host_graph_sw_dataflow.o: ../src/BFS/host/host_graph_sw_dataflow.cpp ../src/BFS/host/host_graph_sw.h ../src/BFS/host/host_graph_scheduler.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/host_graph_sw_kernel.o: ../src/BFS/host/host_graph_sw_kernel.cpp ../src/BFS/host/host_graph_sw.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/host_graph_sw_mem.o: ../src/BFS/host/host_graph_sw_mem.cpp ../src/BFS/host/host_graph_sw.h ../src/BFS/host/he_mem_config.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/host_graph_sw_partition.o: ../src/BFS/host/host_graph_sw_partition.cpp ../src/BFS/host/host_graph_sw.h ../src/BFS/host/host_graph_scheduler.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/host_graph_verification_apply.o: ../src/BFS/host/host_graph_verification_apply.cpp ../src/BFS/host/host_graph_sw.h ../src/BFS/host/config.h ../src/BFS/libfpga/fpga_application.h ../src/BFS/host/host_graph_verification.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/host_graph_verification_gs.o: ../src/BFS/host/host_graph_verification_gs.cpp ../src/BFS/host/host_graph_sw.h ../src/BFS/host/config.h ../src/BFS/libfpga/fpga_application.h ../src/BFS/host/host_graph_verification.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/host_run_one_iteration.o: ../src/BFS/host/host_run_one_iteration.cpp ../src/BFS/host/host_run_one_iteration.h ../../../../..$(XILINX_VIVADO)/include/ap_int.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/l3DataPrepare.o: ../src/BFS/host/l3DataPrepare.cpp ../src/BFS/host/host_graph_sw.h ../src/BFS/libfpga/fpga_application.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/scheduler.o: ../src/BFS/host/scheduler.cpp ../src/BFS/host/host_graph_sw.h ../src/BFS/host/host_graph_scheduler.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

src/BFS/host/xcl.o: ../src/BFS/host/xcl.c ../src/BFS/host/xcl.h
	-@mkdir -p $(@D)
	$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"

$(HOST_EXE): $(HOST_OBJECTS)
	$(HOST_CXX) -o "$@" $(+) $(LDFLAGS)

#
# emulation configuration file
#

$(EMCONFIG_FILE): makeemconfig.mk
	$(EMCONFIGUTIL) --nd $(NUMBER_OF_DEVICES)  --platform $(VITIS_PLATFORM_PATH)
	-@$(RMDIR) TempConfig .Xil/configutil*

